<template>
  <div class="detailFoods" v-if="isShow">
    <div class="foods_swap">
      <div class="foods_img">
        <img v-lazy="foods.image" alt="" />
        <span class="materials overflow">{{ foods.info }}</span>
      </div>
      <div class="food_introduce">
        <h3 class="food_title">{{ foods.name }}</h3>
        <span class="food_sales"
          >月售{{ foods.sellCount }}份 好评率{{ foods.rating }}%</span
        >
        <div class="food_footer">
          <span class="food_price"
            ><strong class="price">￥{{ foods.price }}</strong></span
          >
          <span class="food_cart">
            <transition name="move1">
              <span
                class="btn_Num"
                @click="updateFoodsNum(false)"
                v-if="foods.count"
                >-</span
              >
            </transition>
            <input
              type="text"
              v-model="foods.count"
              class="input_value"
              v-if="foods.count"
            />
            <span class="btn_Num" @click="updateFoodsNum(true)">+</span>
          </span>
        </div>
      </div>
      <div class="icon" @click="hiddenDeatil">
        <i class="iconfont">&#xe650;</i>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: ['foods'],
  data() {
    return {
      isShow: false
    }
  },
  methods: {
    showHidden() {
      this.isShow = !this.isShow
    },
    // 点击隐藏
    hiddenDeatil() {
      this.isShow = false
    },
    // 添加购物车的点击
    updateFoodsNum(isAdd) {
      this.$store.dispatch('updateFoodsNum', { isAdd, foods: this.foods })
    }
  }
}
</script>
<style lang="less" scoped>
.move1-enter-active,
.move1-leave-active {
  transition: all 0.4s;
}
.move1-enter,
.move1-leave-to {
  transform: translateX(18px) rotate(280deg);
}
.icon {
  i {
    color: white;
    font-size: 18px;
    position: absolute;
    top: 9px;
    left: 4px;
  }
}
.detailFoods {
  position: fixed;
  top: 0;
  height: 100%;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 99;
  right: 0;
  left: 0;
  bottom: 0;
  .foods_swap {
    height: 400px;
    width: 300px;
    background-color: white;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    .foods_img {
      height: 300px;
      position: relative;
      img {
        height: 100%;
        width: 100%;
      }
      .materials {
        color: white;
        position: absolute;
        bottom: 8px;
        left: 8px;
        display: block;
        width: 260px;
      }
    }
    .food_introduce {
      padding: 8px;
      .food_title {
        font-weight: 600;
        font-size: 17px;
      }
      .food_sales {
        display: block;
        font-size: 14px;
        color: #999;
        margin-top: 10px;
      }
      .food_footer {
        margin-top: 30px;
        position: relative;
        .price {
          color: red;
          font-size: 14px;
        }
        .food_cart {
          display: inline-block;
          position: absolute;
          right: 0;
          bottom: 0;
          .btn_Num {
            height: 20px;
            width: 20px;
            border-radius: 50%;
            display: inline-block;
            background-color: green;
            color: white;
            text-align: center;
            line-height: 20px;
            font-size: 20px;
            vertical-align: middle;
          }
          .input_value {
            height: 20px;
            border: 1px solid #ccc;
            width: 30px;
            margin: 0 3px;
            text-align: center;
            font-size: 11px;
          }
        }
      }
    }
  }
}
</style>
